﻿using MediatR;
using Traceability.APP.Application.Command.DCompany;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.DCompany
{
    /// <summary>
    /// 深加工企业的显示
    /// </summary>
    public class ShowDeepcompanyCommandHandle:IRequestHandler<ShowDeepcompanyCommand,APIResult<List<DeepCompany_Model>>>
    {
        private readonly IBaseRepository<DeepCompany_Model> DCDal;

        public ShowDeepcompanyCommandHandle(IBaseRepository<DeepCompany_Model> dCDal)
        {
            DCDal = dCDal;
        }

        public Task<APIResult<List<DeepCompany_Model>>> Handle(ShowDeepcompanyCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<DeepCompany_Model>> result = new APIResult<List<DeepCompany_Model>>();
            var list = DCDal.GetAll().Where(x => x.Batch == request.Batch && x.IsDeleted == false);
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }


    }
}
